package cn.nebula.music.token;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import cn.nebula.music.utils.MD5Utils;

public class TokenUtil {

	 public static  String generateToken(String username) throws NoSuchAlgorithmException, UnsupportedEncodingException {
	        StringBuilder token = new StringBuilder();
	        //加token:
	        token.append("token:");
	        //加加密的用户名
	        token.append(MD5Utils.encrypt(username) + "-");
	        //加时间
	        token.append(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + "-");
	        //加六位随机数111111-999999
	        token.append(new Random().nextInt((999999 - 111111 + 1)) + 111111);
	        System.out.println("token=>" + token.toString());
	        return token.toString();
	    }
}
